#ifndef _GATEWAY_PROTOCOL_H_
#define _GATEWAY_PROTOCOL_H_

#include <string>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>


class gateway_protocol : public boost::enable_shared_from_this<gateway_protocol>
{
typedef struct{
    std::string srcdata; //原始数据帧
    std::string rssi; //当前数据包信号指示
    std::string mac; //设备 IMEI
    std::string rorg; //数据帧类型码 A5
    std::string func; //插座（排插）  23
    std::string type; //功能分类Default(“01”)
    std::string sn; //帧号
    std::string ticks; //当前数据包生成的系统 tick 时间 单位10ms
    std::string vt; //电压数据
    std::string current; //电流
    std::string watt; //有功功率
    std::string wkh; //总电量
    std::string factor; //功率因素
    std::string frelay; //负载通断状态
    std::string remoteaddr; //远端地址
    std::string localaddr; //本地地址
    std::string retime; //上报时间间隔
    //std::string ip; //中心IP
    //std::string port;
    //std::string sw; //通断状态 00:关 01:开
}StateInfo;//与keyname[]一一对应

public:
    gateway_protocol(std::string ip, int port);

public:
    int init(std::string ip, int port);
    int prase(const unsigned char* data, int datalen);
    int make();
    std::string get_json_buf();
    std::string get_devid();
    std::string get_ctrcmddata(std::string strkey, std::string strval);
    int get_retime();

private:
    std::string make_json(StateInfo* state);
private:
    std::string m_strbuf;
    std::string m_devid;
    std::string m_ip;//中心ip
    int m_port;
    StateInfo m_state;

};
typedef boost::shared_ptr<gateway_protocol>gateway_protocol_ptr;

#endif /*_GATEWAY_PROTOCOL_H_*/